import { ComputedRef, reactive } from "vue";
interface pageOptions {
    current: number;
    pageSize: number;
    total: number | ComputedRef<unknown>;
}

export default function usePage() {
    const pagination = reactive<pageOptions>({
        current: 1,
        pageSize: 10,
        total: 0,
    });

    let _afterFunc = function () {/***/ }

    function changePage(page: number, pageSize: number) {
        pagination.current = page
        pagination.pageSize = pageSize
        _afterFunc()
    }

    function showSizeChange(page: number, pageSize: number) {
        pagination.current = page
        pagination.pageSize = pageSize
        _afterFunc()
    }

    function setPageChangeFunc(func: () => void) {
        _afterFunc = func
    }


    return {
        pagination,
        changePage,
        showSizeChange,
        setPageChangeFunc
    }
}